package com.yanqu.road.server.cmd.patrons;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.CombLeaderModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_PATRONS_KEEP_SAKE_RELATION_ADD, desc = "信物羁绊绑定")
public class PatronsKeepSakeRelationAddCmd extends AbstractCommand {

    int patronsId;
    int selectPatronsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PatronsProto.PatronsKeepSakeRelationAddReqMsg reqMsg = PatronsProto.PatronsKeepSakeRelationAddReqMsg.parseFrom(packet.getBytes());
        patronsId = reqMsg.getPatronsId();
        selectPatronsId = reqMsg.getSelectPatronsId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (PatronsMgr.haveCombLeader(patronsId)){
            ret = player.getModule(CombLeaderModule.class).keepSakeRelation(patronsId, selectPatronsId);
        }else {
            ret = player.getModule(PatronsModule.class).keepSakeRelation(patronsId, selectPatronsId);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_PATRONS_KEEP_SAKE_RELATION_ADD, PatronsProto.PatronsKeepSakeRelationAddRespMsg.newBuilder().setRet(ret));
        }
    }
}
